#pragma once
#include "mq_msg/mq_msg.pb.h"
#include "helper.hpp"
#include "log.hpp"
#include <iostream>
#include <functional>
#include <mutex>
#include <memory>

namespace xzt
{
    // 回调函数参数：消费者标识、消息基本属性、消息内容
    using ConsumerCallback = std::function<void(const std::string &tag,
                                                const xzt::BasicPropeties *bp, const std::string &body)>;
    
    class Consumer
    {
    public:
        using ptr = std::shared_ptr<Consumer>;

    public:
        Consumer() = default;
        Consumer(const std::string &tag, const std::string &queue_name, bool auto_ack, const ConsumerCallback &callback): 
                _tag(tag), _queue_name(queue_name), _auto_ack(auto_ack), _callback(callback) 
        {
            DLOG("consumer is created, tag: %s, queue_name: %s", tag.c_str(), queue_name.c_str());
        }

        ~Consumer()
        {
            DLOG("consumer is destroyed, tag: %s, queue_name: %s", _tag.c_str(), _queue_name.c_str());
        }

    public:
        std::string _tag;           // 消费者标识
        std::string _queue_name;    // 消费者订阅的队列名称
        bool _auto_ack;             // 是否自动确认消息
        ConsumerCallback _callback; // 消费者回调函数
    };
}